home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / SICN_LDE / SICN_LDE.C next >
C/C++ Source or Header  |  1989-12-22  |  4KB  |  188 lines

  1. /*
  2.     sicn ldef.c  v1.0
  3.     Copyright 1989 Josh Pritikin
  4.     All rights reserved.
  5.     
  6.     This LDEF may be used freely in any programming project, no string attached.
  7.     
  8.     This LDEF will let you display text as with a normal LDEF except you can
  9.     also attach SICN's to each item.  I wrote this to emulate the one in SFDialog.
  10.     
  11.     The data format is as follows:
  12.     
  13.     char    index into the SICN resource
  14.     Pstr    the item's text
  15.     
  16.     The SICN used is the one that has the same ID as the LDEF.  The SICN id
  17.     could be uptained in a more versital way but I didn't want to spend too
  18.     much time on this mini-project.
  19.     
  20.     If you add color capabilities or figure out a better way to specify the
  21.     SICN id, send me a copy of your source.
  22.     
  23.     
  24.     Change History
  25.  
  26. 12.19.89    Created and tested.
  27. 12.19.89    v1.0 Release
  28. 12.19.89    Now the high bit of the sicn index indicates whether to hilite the
  29.             item or not.  Set means disabled.
  30. 12.22.89    If the item is disabled you can't select it anymore. Your appl will
  31.             have to check because the List Mgr thinks the item is selected but
  32.             it wont show on screen.
  33. 12.19.89    v1.02 Release - (sorry 'bout not making this the first release)
  34.     
  35.     I can be reached at different speed at:
  36.     
  37. fast->            (every day)
  38.     internet: 6500stom@ucsbuxa.ucsb.edu
  39.     AppleLink: 6500stom%ucsbuxa@hub.ucsb.edu@DASNET#
  40.     CIS: >INTERNET:6500stom%ucsbuxa@hub.ucsb.edu
  41. slow->            (once a week)
  42.     GEnie: J.Pritikin
  43.     AppleLink: Josh.P
  44. very slow->        (once a month, if yer lucky)
  45.     CIS: 70771,2131
  46. */
  47.  
  48. typedef unsigned char    uchar;
  49.  
  50. /* #define testing */
  51.  
  52. #ifdef testing
  53. pascal void ldef128(int message, Boolean select, Rect *bounds, Cell cell,
  54.     int DataOff, int DataLen, ListHandle lhandle)
  55. #else
  56. pascal void main(int message, Boolean select, Rect *bounds, Cell cell,
  57.     int DataOff, int DataLen, ListHandle lhandle)
  58. #endif
  59. {
  60.     Rect    savedOrig;
  61.     GrafPtr    aPort, saveport;
  62.     int        savedFont, savedSize, savedMode, savedPenVis;
  63.     Style    savedFace;
  64.     PenState    ps;
  65.  
  66.     if (message == lDrawMsg || message == lHiliteMsg) {
  67.         GetPort(&saveport);
  68.         aPort = (**lhandle).port;
  69.         SetPort(aPort);
  70.         
  71.         savedOrig = aPort->portRect;
  72.         SetOrigin(0,0);
  73.         savedPenVis = aPort->pnVis;
  74.         aPort->pnVis = 0;
  75.         GetPenState(&ps);
  76.         
  77.         savedFont = aPort->txFont;
  78.         savedSize = aPort->txSize;
  79.         savedFace = aPort->txFace;
  80.         savedMode = aPort->txMode;
  81.         TextFont(systemFont);
  82.         TextSize(0);
  83.         TextFace(0);
  84.         TextMode(srcOr);
  85.     }
  86.     
  87.     switch (message) {
  88.     case lInitMsg:
  89.         {
  90.         int        id;
  91.         long    type;
  92.         Str255    name;
  93.         
  94.         GetResInfo((**lhandle).listDefProc, &id, &type, &name);
  95.         (**lhandle).userHandle = GetResource('SICN', id);
  96.         HPurge((**lhandle).userHandle);
  97.         
  98.         break;
  99.         }
  100.         
  101.     case lDrawMsg:
  102.         {
  103.         Handle    sicns;
  104.         uchar    index;
  105.         Boolean    hilited;
  106.         
  107.         EraseRect(bounds);
  108.         MoveTo(bounds->left + 22, bounds->bottom - 4);
  109.         DrawText(*(**lhandle).cells, DataOff+1, DataLen-1);
  110.         
  111.         index = *(*(Handle)(**lhandle).cells + DataOff);
  112.         if (index >= 0x80) {
  113.             index = index & 0x7f;
  114.             hilited = false;
  115.         } else
  116.             hilited = true;
  117.         
  118.         if (btwn(index, 0, 5)) {
  119.             sicns = (**lhandle).userHandle;
  120.             if (sicns) {
  121.                 LoadResource(sicns);
  122.                 if (*sicns) {
  123.                     BitMap    bmap;
  124.                     Rect    r;
  125.                     
  126.                     HNoPurge(sicns);
  127.                     HLock(sicns);
  128.                     
  129.                     bmap.baseAddr = *sicns+(index * 32);
  130.                     SetRect(&bmap.bounds, 0, 0, 16, 16);
  131.                     bmap.rowBytes = 2;
  132.                     
  133.                     r = bmap.bounds;
  134.                     OffsetRect(&r, bounds->left+3, bounds->top);
  135.                     
  136.                     CopyBits(&bmap, &aPort->portBits, &bmap.bounds, &r, srcOr,
  137.                         nil);
  138.                     
  139.                     HUnlock(sicns);
  140.                     HPurge(sicns);
  141.                 }
  142.             }
  143.         }
  144.         
  145.         if (!hilited) {
  146.             long    gray[2];
  147.             
  148.             PenMode(patBic);
  149.             gray[0] = gray[1] = 0xaa55aa55;        /* 50% gray */
  150.             PenPat(gray);
  151.             PaintRect(bounds);
  152.         }
  153.         
  154.         if (!select)
  155.             break;
  156.         }
  157.         
  158.     case lHiliteMsg:
  159.         {
  160.         /* mail me if you figure out how to hilite in color in a BW port
  161.            I suspect you open a new color port, draw and trash it */
  162.         
  163.         if (*(*(Handle)(**lhandle).cells + DataOff) < 0x80)
  164.             InvertRect(bounds);
  165.         break;
  166.         }
  167.         
  168.     case lCloseMsg:
  169.         {
  170.         if ((**lhandle).userHandle)
  171.             ReleaseResource((**lhandle).userHandle);
  172.         break;
  173.         }
  174.     }
  175.  
  176.     if (message == lDrawMsg || message == lHiliteMsg) {
  177.         SetPenState(&ps);
  178.         aPort->pnVis = savedPenVis;
  179.         aPort->portRect = savedOrig;
  180.         TextFont(savedFont);
  181.         TextSize(savedSize);
  182.         TextFace(savedFace);
  183.         TextMode(savedMode);
  184.         
  185.         SetPort(saveport);
  186.     }
  187. }
  188.